const BASE_URL = "https://tea.qingnian8.com/api/bizhi";
export function request(config = {}) {
  let {
    url,
    method,
    data,
    header = {}
  } = config
  url = BASE_URL + url
  header["access-key"] = "210629"
  return new Promise((resolve, reject) => {
    uni.request({
      url,
      method: method || 'GET',
      data: data || {},
      header,
      timeout: 5000,
      success: (res) => {
        if (res.data.errCode === 0) {
          resolve(res.data)
        } else if (res.data.errCode === 400) {
          uni.showModal({
            title: "错误提示",
            content: res.data.errMsg,
            showCancel: false
          })
          reject(res.data)
        } else {
          uni.showToast({
            title: res.data.errMsg,
            icon: "none"
          })
          reject(res.data)
        }
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}